/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example.photongrid;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;

/**
 *
 * @author 
 */
public class GameStateClient extends AbstractAppState {
    
    StateManagerClient game;
    UpdateQuadTree gameUpdate;
    Thread updateGameThread;
    
    GameStateClient()
    {
        game = null;
        gameUpdate = null;
        updateGameThread = null;
    }
    
    @Override
    public void initialize(AppStateManager stateManager, Application app)
    {
        super.initialize(stateManager, app);
        
        game = (StateManagerClient) app;
        
        game.initializeGame();  
        /*
        gameUpdate = new UpdateQuadTree(game.board);
        
        updateGameThread = new Thread(gameUpdate);
        
        updateGameThread.start();
        
		updateGameThread.interrupt();
		*/
        
    }
    
    
    @Override
    public void setEnabled(boolean enabled)
    {
      // Pause and unpause
      super.setEnabled(enabled);
      /*if(enabled){
    	  //updateGameThread.notify();
        // init stuff that is in use while this state is RUNNING
        //this.game.getRootNode().attachChild(); // modify scene graph...
      } else {
        // take away everything not needed while this state is PAUSED
        //...
    	  try {
    		  if(updateGameThread.isInterrupted()){
    			  
    		  }
    		  else
    		  {
    				updateGameThread.wait();
    		  }
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
      }*/
    }
    
    @Override
    public void update(float tpf) {
      // do the following while game is RUNNING
      game.updateGame();
    }
}
